// cd /projects/hsieh_project/proj_201809/code_2_202011/
// qstata city_new_ind_sales_share_top_sales.do &

set linesize 255
capture log close
log using /projects/hsieh_project/proj_201809/code_2_202011/city_new_ind_sales_share_top_sales_log, replace text

clear all
cd /projects/

di "Started at $S_TIME $S_DATE"

global rev_date: display %tdYYNNDD date("$S_DATE", "DMY")
di "${rev_date}"

global dir_proj "/projects/hsieh_project/proj_201809/"

global dir_do "${dir_proj}/code_2_202011/"
global dir_data "${dir_proj}/data/"
global dir_out "${dir_proj}/output/202011_main/"
noi capture mkdir ${dir_out}
global dir_outf "${dir_out}/city_new_ind_sales_share_top_sales/"
noi capture mkdir ${dir_outf}

global year1 = 1977
global year2 = 2013

global gl_perc = "1 10"
local l_perc = "1 10"


do "/projects/hsieh_project/code_0_general/f_rounding.do"
do "/projects/hsieh_project/code_0_general/f_reg.do"

global ds_ind "${dir_data}/ind_sum_all"

//==============================================================================
/*
Author: Adarsh Kumar
Objective: Share ofsales in each msa1983 of new industries in 2012 (compared to 1977), where share is calculated as:

1. Total Sales in new ind in city / Total Sales in City 

Plot this against Employment in MSA in 1977

*/

use "${dir_data}/sales_new_ind_share.dta", clear
gen ln_emp_msa1983_1977 = ln(emp_msa83_1977)

program f_fig_wo_scatter
args y y_lab y_save note

twoway (lpolyci `y' ln_emp_msa1983_1977, level(99) clc(navy) clw(medthick) fc(none) alcolor(gs12)), ///
	ytitle("Share of Sales") xtitle("ln(City Employment in ${year1})") ///
	title("`y_lab'") ///
	legend(off) ///
	note("99% CI. `note'")
graph export "${dir_outf}/lpoly_`y_save'_X_ln_c_emp_${year1}_msa1983.png", replace width(3000) height(2000)


end

* f_fig_wo_scatter "sales_new_sh" "Sales in New Ind / MSA1983 Sales" "new_ind_all"

use "${dir_data}/sales_new_ind_top_share.dta", clear
gen ln_emp_msa1983_1977 = ln(emp_msa83_1977)
gen ln_emp_msa1983_1977_4sf = ln_emp_msa1983_1977

gen sales_new_sh_4sf = sales_new_sh

